package work.jame.blog.framework.result;


import java.io.Serializable;

/**
 * 封装的返回结果
 *
 * @author : Jame
 * @date : 2022-08-12 09:34
 **/
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private T data;
    private Integer code;
    private String message;

    public Result(T data, Integer code, String message) {
        this.data = data;
        this.code = code;
        this.message = message;
    }

    public static <T> Result<T> succeed() {
        return create(null, ServerStatusCode.SUCCESS, "操作成功");
    }

    public static <T> Result<T> succeed(T data) {
        return create(data, ServerStatusCode.SUCCESS, "操作成功");
    }

    public static <T> Result<T> succeedMessage(String message) {
        return create(null, ServerStatusCode.SUCCESS, message);
    }

    public static <T> Result<T> message(String message) {
        return create(null, 200, message);

    }

    public static <T> Result<T> succeed(T data, String message) {
        return create(data, ServerStatusCode.SUCCESS, message);
    }

    public static <T> Result<T> fail() {
        return create(null, ServerStatusCode.FAIL, "操作失败");
    }

    public static <T> Result<T> fail(String message) {
        return create(null, ServerStatusCode.FAIL, message);
    }

    public static <T> Result<T> noData() {
        return create(null, ServerStatusCode.FAIL, "没有对应的数据");
    }

    public static <T> Result<T> fail(T data, String message) {
        return create(data, ServerStatusCode.FAIL, message);
    }

    public static <T> Result<T> error() {
        return create(null, ServerStatusCode.ERROR, "服务异常");
    }

    public static <T> Result<T> create(T data, Integer code, String message) {
        return new Result<T>(data, code, message);
    }


    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
